import { useEffect, useRef } from "react";

function useFangdou(callBack, delay) {
  const timer = useRef(null);
  useEffect(() => {
    return () => {
      if (timer.current) {
        clearTimeout(timer.current);
      }
    };
  });

  return (...arg) => {
    if (timer.current) {
      clearTimeout(timer.current);
    }

    timer.current = setInterval(()=>{
        callBack(...arg)
    },delay)
  };
}

export default useFangdou;
